<div class="profile-wrapper"> 
    <? if($admin['avatar_version']): ?>
        <img width="70" height="70" src="<?= DATA_DOMAIN."admin/{$admin['admin_id']}/avatar_upload_thumb.png?v={$admin['avatar_version']}" ?>">
    <? endif ?>
</div>
<h1 class="light">
    <?= $admin['username'] ?><span class="semi-bold"> <?= $admin['nickname'] ?></span>
</h1>
<p class="muted">上次登录：<?= time_format($admin['last_login']) ?></p>

<div class="row">
    <div class="col-md-12">
        <div id="tabs">
            <ul class="nav nav-tabs">
                <li class="active">
                    <a href="#basic-info" data-toggle="tab">基本信息</a>
                </li>
                <li class="">
                    <a href="#password-info" data-toggle="tab">修改密码</a>
                </li>
                <li class="">
                    <a href="#priv-info" data-toggle="tab">角色权限</a>
                </li>
            </ul>
        </div>
        <div class="tab-content">
            <div id="basic-info" class="tab-pane active">
                <div class="row column-seperation">
                    
                    <div class="col-md-6">
                        <form class="form-no-horizontal-spacing" method="POST" action="<?= DOMAIN.'center/profile' ?>">
                        <div class="form-group">
                            <label class="form-label">昵称</label>
                            <input type="text" placeholder="昵称" class="form-control" name="nickname" value="<?= $temp['nickname'] ? $temp['nickname'] : $admin['nickname'] ?>" />
                        </div>

                        <div class="form-group">
                            <label class="form-label">性别</label>
                            <div class="radio">
                                <? foreach($admin_gender as $k => $v): ?>
                                    <? if($temp['gender'] == $k || ( ! $temp && $admin['gender'] == $k)): ?>
                                        <input type="radio" checked="checked" value="<?= $k ?>" name="gender" id="<?= $k ?>">
                                    <? else: ?>
                                        <input type="radio" value="<?= $k ?>" name="gender" id="<?= $k ?>">
                                    <? endif ?>
                                    <label for="<?= $k ?>"><?= $v ?></label>
                                <? endforeach ?>
                            </div>
                        </div>

                        <div class="form-row">
                            <label class="form-label">邮箱</label>
                            <input type="text" placeholder="email@address.com" class="form-control" name="email" value="<?= $temp['email'] ? $temp['email'] : $admin['email'] ?>" >
                        </div>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <br>
                        <div class="form-row">
                            <button type="submit" class="btn btn-success btn-cons">
                                <i class="icon-ok"></i>&nbsp;保存
                            </button>
                            <button type="reset" class="btn btn-white btn-cons">取消</button>
                        </div>
                        </form>
                    </div>

                    <div class="col-md-5">
                        <div class="form-group">
                            <label class="form-label">上传头像</label>
                            <ol class="">
                                <li>支持格式.png .jpg/jpeg .gif。</li>
                                <li>图片大小不能超过1M（您上传的图片会被压缩的，再大也没用）。</li>
                                <li>图片最好为正方形（不然会后悔的）。</li>
                            </ol>
                            <form action="" class="dropzone" id="dropzone-avatar">
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <div id="password-info" class="tab-pane">
                <div class="row">
                    <div class="col-md-6">
                        <form id="form-password" method="POST" action="<?= DOMAIN.'center/change_password' ?>">
                            <div class="form-group">
                                <label class="form-label">旧密码</label>
                                <input type="password" class="form-control" id="old_password" name="old_password" value=""/>
                            </div>

                            <div class="form-group">
                                <label class="form-label">新密码</label>
                                <input type="password" class="form-control" id="new_password" name="new_password" value=""/>
                            </div>

                            <div class="form-group">
                                <label class="form-label">确认新密码</label>
                                <input type="password" class="form-control" id="new_password_confirm" name="new_password_confirm" value="" />
                            </div>
                            <br>
                            <br>
                            <div class="form-row">
                                <button type="submit" class="btn btn-success btn-cons">
                                    <i class="icon-ok"></i>&nbsp;保存
                                </button>
                                <button type="button" onclick="$.T.reset_form(this)" class="btn btn-white btn-cons">取消</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <div id="priv-info" class="tab-pane">
                <? if($role_resource): ?>
                    <table class="table table-bordered no-more-tables">
                        <colgroup>
                            <col />
                            <col width="10%" />
                        </colgroup>
                        <thead>
                            <tr>
                                <th>程序名</th>
                                <? foreach($role_resource_group as $item): ?>
                                    <th><?= $item ?></th>
                                <? endforeach ?>
                            </tr>
                        </thead>
                        <tbody>
                            <? foreach($role_resource as $r): ?>
                                <tr>
                                    <td>
                                        <?= $r['name'] ?>
                                    </td>
                                    <? foreach($role_resource_group as $rg => $rgv): ?>
                                    <td>
                                        <? $id = "PRIV-{$r['resource_id']}-{$rg}" ?>
                                        <div class="checkbox check-success">
                                            <? if(is_array($admin['privs'])): ?>
                                                <!-- 当前拥有的权限 -->
                                                <input type="checkbox" <?= in_array("{$r['resource_id']}-{$rg}", $admin['privs']) ? 'checked="checked"' : '' ?> value="" id="<?= $id ?>" disabled="disabled" />
                                            <? endif ?>
                                            
                                            <label for="<?= $id ?>"></label>
                                        </div>
                                    </td>
                                    <? endforeach ?>
                                </tr>
                            <? endforeach ?>
                        </tbody>
                    </table>
                <? endif ?>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){

        // 上传头像
        $("#dropzone-avatar").dropzone({ 
            url           : $.G.domain+"center/upload_avatar",
            method        : 'POST',
            maxFilesize   : 1024,
            paramName     : 'avatar_upload',
            uploadMultiple: false,
            acceptedFiles : 'image/*',
            success       : function(file){
                $.T.alert("头像上传成功！", function(){
                    $.T.refresh();
                });
            }
        });

        // tabs
        $('#tabs').tab('show')

        // 表单验证
        $('#form-password').validate({
            rules: {
                old_password: "required",
                new_password: "required",
                new_password_confirm: {
                    equalTo: "#new_password"
                }
            }
        });
    });
</script>